<template>
  <!-- 一条文章单元格 -->
  <van-cell @click="dj">
    <!-- 标题区域的插槽 -->
    <template #title>
      <div class="title-box" >
        <!-- 标题 -->
        <span>{{ obj.title }}</span>
        <img
          class="thumb"
          v-if="obj.cover.type === 1"
          :src="obj.cover.images[0]"
          lazy-load
          alt=""
        />
      </div>
      <div v-if="obj.cover.type > 1" class="thumb-box">
        <img
          v-for="(imgUrl, index) in obj.cover.images"
          :key="index"
          :src="imgUrl"
          alt=""
          class="thumb"
          lazy-load
        />
      </div>
    </template>
    <!-- label 区域的插槽 -->
    <template #label>
      <div class="label-box">
        <div>
          <span>{{ obj.aut_name }}</span>
          <span>{{ obj.comm_count }}评论</span>
          <span>{{ formatTime(obj.pubdate) }}</span>
        </div>
        <!-- 反馈按钮 -->
        <van-icon name="cross" @click.stop="show = true" v-show="isShow" />
        <van-action-sheet
          v-model="show"
          :actions="actions"
          @select="onSelect"
          :cancel-text="qvorfh"
          @cancel="onCancel"
          @closed = "onClosed"
          get-container="body"
        />
      </div>
    </template>
  </van-cell>
</template>

<script>
import { timeAgo } from '@/utils/date.js'

import { firstActions, secondActions } from '@/api/report.js'
export default {
  data () {
    return {
      show: false,
      actions: firstActions,
      qvorfh: '取消'

    }
  },
  props: {
    obj: {
      type: Object
    },
    isShow: {
      type: Boolean
    }
  },
  methods: {
    formatTime: timeAgo,
    onSelect (action, index) {
      if (action.name === '反馈垃圾内容') {
        this.actions = secondActions
        this.qvorfh = '返回'
      } else if (action.name === '不感兴趣') {
        this.$emit('disLikeEV', this.obj.art_id)
        this.show = false
      } else {
        this.$emit('reportEV', this.obj.art_id, action.value)
        this.show = false
      }
    },
    onCancel () {
      if (this.qvorfh === '返回') {
        this.show = true
        this.actions = firstActions
        this.qvorfh = '取消'
      }
    },
    onClosed () {
      this.actions = firstActions
      this.qvorfh = '取消'
    },
    dj () {
      // this.$emit('clickEv')
      this.$router.push({
        path: `/detail/${this.obj.art_id}`
      })
    }
  }
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span {
  margin: 0 3px;
  &:first-child {
    margin-left: 0;
  }
}
/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
